/**
 * @copyright 2025 银杏ERP
 * @author 银杏ERP
 * @version 1.0
 * @license http://www.hhyx.xyz
 * @developer Lhf
 */

import createAxios from '/@/utils/axios'
import { useAdminInfo } from '/@/stores/adminInfo'
import { useSiteConfig } from '/@/stores/siteConfig'

const adminInfo = useAdminInfo()
const siteConfig = useSiteConfig()
const controllerUrl = '/admin/yxerp.warehouse/'

export function getWarehouseList(params: object = {}) {
    return createAxios({
        url: controllerUrl + 'index',
        method: 'get',
        params: {
            ...params,
        },
    })
}

export function getWarehouseInfo(id: string) {
    return createAxios({
        url: controllerUrl + 'edit',
        method: 'get',
        params: {
            ids: id,
        },
    })
}

export function addWarehouse(data: object) {
    return createAxios(
        {
            url: controllerUrl + 'add',
            method: 'post',
            data: data,
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function editWarehouse(data: object) {
    return createAxios(
        {
            url: controllerUrl + 'edit',
            method: 'post',
            data: data,
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function delWarehouse(ids: string[]) {
    return createAxios(
        {
            url: controllerUrl + 'del',
            method: 'post',
            data: {
                ids: ids,
            },
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function getWarehouseSelect() {
    return createAxios({
        url: controllerUrl + 'select',
        method: 'get',
    })
}

// 仓库出入库操作API
const operationUrl = '/admin/yxerp.warehouse_operation/'

export function getOperationList(params: object = {}) {
    return createAxios({
        url: operationUrl + 'index',
        method: 'get',
        params: {
            ...params,
        },
    })
}

export function getOperationInfo(id: string) {
    return createAxios({
        url: operationUrl + 'edit',
        method: 'get',
        params: {
            ids: id,
        },
    })
}

export function getOperationDetail(id: string) {
    return createAxios({
        url: operationUrl + 'detail',
        method: 'get',
        params: {
            ids: id,
        },
    })
}

export function addOperation(data: object) {
    return createAxios(
        {
            url: operationUrl + 'add',
            method: 'post',
            data: data,
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function editOperation(data: object) {
    return createAxios(
        {
            url: operationUrl + 'edit',
            method: 'post',
            data: data,
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function delOperation(ids: string[]) {
    return createAxios(
        {
            url: operationUrl + 'del',
            method: 'post',
            data: {
                ids: ids,
            },
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function approveOperation(id: string) {
    return createAxios(
        {
            url: operationUrl + 'approve',
            method: 'post',
            params: {
                ids: id,
            },
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function unapproveOperation(id: string) {
    return createAxios(
        {
            url: operationUrl + 'unapprove',
            method: 'post',
            params: {
                ids: id,
            },
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function cancelOperation(id: string) {
    return createAxios(
        {
            url: operationUrl + 'cancel',
            method: 'post',
            params: {
                ids: id,
            },
        },
        {
            showSuccessMessage: true,
        }
    )
}

export function getOperationTypes() {
    return createAxios({
        url: operationUrl + 'getOperationTypes',
        method: 'get',
    })
} 